package com.sales.service.impl;


import com.sales.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

@Service
public class VerificationCodeServiceImpl implements VerificationCodeService {


    @Autowired
    StringRedisTemplate stringRedisTemplate;


    /**
     * 验证码生产
     *
     * @param mobile
     * @return
     */
    public void setCode(String mobile) {
        Random ne = new Random();//实例化一个random的对象ne
        Integer code = ne.nextInt(9999 - 1000 + 1) + 1000;//为变量赋随机值1000-9999
        Map map = new HashMap();
        map.put("code", code);
        // AliSMSUtil.sendSms(mobile, map, AliTemplateCodeEnums.ALI_MSS_CODE.getCode());
        stringRedisTemplate.opsForValue().set(mobile, code.toString());
    }
}
